package com.example.social.item_view

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import coil.compose.AsyncImage
import com.example.social.model.CommentModel
import com.example.social.navigation.Routes

@Composable
fun CommentItem(comment: CommentModel, navHostController: NavHostController) {
    Column(modifier = Modifier.padding(top = 10.dp, start = 10.dp)) {
        Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.clickable {
            val route = Routes.OtherUsers.routes.replace("{data}", comment.uid)
            //进入详情页
            navHostController.navigate(route)
        }) {
            AsyncImage(
                model = comment.imageUrl,
                contentDescription = "User Avatar",
                modifier = Modifier
                    .size(30.dp)
                    .clip(CircleShape),
                contentScale = ContentScale.Crop
            )
            Spacer(modifier = Modifier.width(10.dp))
            // 显示昵称
            Text(text = comment.nickname, fontWeight = FontWeight.Bold)
        }
        Column(horizontalAlignment = Alignment.Start, modifier = Modifier.fillMaxWidth().clickable {
            val route = Routes.ThreadDetailScreen.routes.replace("{data}", comment.tid.toString())
            //进入详情页
            navHostController.navigate(route)
        }) {
            Spacer(modifier = Modifier.height(10.dp))
            Text(
                text = comment.content,
                style = TextStyle(fontSize = 14.sp),
                modifier = Modifier.padding(start = 35.dp)
            )
            Spacer(modifier = Modifier.height(10.dp))
            Text(
                text = comment.created,
                style = TextStyle(fontSize = 14.sp),
                modifier = Modifier
                    .align(Alignment.End) // 使时间显示在右边
                    .padding(end = 20.dp) // 给时间文本额外的 padding
            )
            Spacer(modifier = Modifier.height(10.dp))
        }
    }
    //下划线
    Box(
        modifier = Modifier
            .fillMaxWidth()
            .height(1.dp)
            .background(Color.LightGray) // 自定义颜色
    )
}
